<?php
require_once("head.php");
if(!is_admin($user))die ("You can't access this file directly...");
#echo jour_p($date,0);
##########################################
function creer_sql() {
##########################################
global $lang,$nr,$HTTP_SERVER_VARS,$wysiwyg,$PHP_SELF;
#print_r($HTTP_SERVER_VARS);
echo"
          <center>
          <table width=\"600\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" >
          <tr>
          <td>
          <form name=\"s\" method=\"post\" action=\"$PHP_SELF\">
          <INPUT TYPE=\"HIDDEN\"  name=\"op\" VALUE=\"envoyer_sql\">";
          input_joueurs ("to","");
#if(!$wysiwyg)echo"<a href=\"".$HTTP_SERVER_VARS["REQUEST_URI"]."&wysiwyg=1\"><img src=\"images/htm.gif\" border=\"0\" alt=\""._WYSIWYG."\" title=\""._WYSIWYG."\" width=\"15\" height=\"20\"></a><br>\n";
#if($wysiwyg)echo"<a href=\"".$HTTP_SERVER_VARS["REQUEST_URI"]."&wysiwyg=0\"><img src=\"images/txt.gif\" border=\"0\" alt=\""._TXT."\" name=\""._TXT."\" width=\"15\" height=\"20\"></a><br>\n";

echo      "<TEXTAREA  name=\"texte\" rows=\"20\" cols=\"60\">$texte</TEXTAREA>
          <br>
          <input type=\"submit\" name=\"Submit\" value=\""._ENVOYER."\">
          </form>
          </td></tr></table></center> ";

}
##########################################
function envoyer_sql(){
##########################################
global $_POST;
print_r($_POST);
$items=explode(" ",$_POST["to"]);
print_r($items);
eregi("([[:alnum:]]*)[ ]*([0-9]{1,3})([0-9]{1,1})",$_POST["texte"],$resultats);
if($resultats[1]="vote"):$resultats[1]="sondage_votes";$champs="id_question,id_choix,identifiant";endif;
foreach($items as $item ){
if ($item){
echo $sql=" INSERT INTO ".$resultats[1]." ($champs) VAlUES ('".$resultats[2]."','".$resultats[2].$resultats[3]."','$item');";
mysql_query($sql);
echo mysql_errno(). ": ".mysql_error(). "<br>";
}

}
print_r( $resultats);

}
######################################
function joueurscript () {
######################################
        echo "<script language='JavaScript'>\n";
        echo "function InsertJoueur(nom,valeur) {\n";
        echo "var flag = (window.Event)? true : false;\n";
        echo "var img = (flag)? ObjE.target : window.event.srcElement;\n";

#        echo "        var img = window.event.srcElement;\n";
        echo "        if (img) {\n";
        echo "                var src = img.src.replace(/^[a-z]*:[/][/][^/]*/, \"\");\n";

        echo "         if ( img.style.border != \"red 1px solid\") {\n
                       img.style.border = \"red 1px solid\" ;\n
                       document.getElementById(nom).value+=valeur+\" \";\n
                       document.getElementById(nom+'preview').style.backgroundImage='url(\''+ src +'\')';\n
                       }else{\n
                       img.style.border= \"black 1px solid\" ;\n
                       document.getElementById(nom).value= document.getElementById(nom).value.replace(valeur+\" \", \"\");\n
                       }\n";
        echo "        }\n";
        echo "}\n";
        echo "</script>\n";
}
######################################
function input_joueurs ($nom,$langue) {
######################################
global $dbi,$lang;
$abr="fr";
if ($lang=="danish")$abr="dk";
joueurscript ();
echo "<table cellpadding=\"0\" cellspacing=\"2\"><tr><td>\n";
         echo "<table cellpadding=\"0\" cellspacing=\"0\"><tr><td>\n";
         echo "<input type='text' name='$nom' value='$langue' size=100 style='font-size: 10px'>\n";
         echo "</td><td>\n";
         echo "<div id=".$nom."preview    style='width: 100;height: 100; background-repeat : no-repeat ; background-position : center;'></div>\n";
         echo "</td></tr></table>\n";
echo "</td>\n</tr\n><tr>\n<td>\n";
        echo "<table border=0 align=center cellpadding=2><tr>";
                        $result=mysql_query("SELECT j.identifiant  FROM rugby_joueurs as j, pays as p where j.identifiant !=''and p.id=j.langue and j.langue='$abr'  ORDER BY Prenom ASC ",$dbi );
                        echo mysql_errno(). ": ".mysql_error(). "<br>";
                        while ($joueur = mysql_fetch_array($result)) {
                                        echo "<td>\n<img border=1  src=\"./images/joueurs/".$joueur["identifiant"].".jpg\" name=\"".$joueur["identifiant"]."\" alt=\"".$joueur["identifiant"]."\" title=\"".$joueur["identifiant"]."\" onclick=InsertJoueur('$nom','".$joueur["identifiant"]."') width=\"40\" height=\"40\"></td>\n";
                                        #echo "<td>".$langues["lang"]."</td>";
                                if ($td++ == 6) {
                                        echo "</tr><tr>\n";
                                        $td = 0;
                                }
                        }
        echo "</tr></table>\n";
echo "</td></tr></table>\n";

}
##########################################

switch ($op) {
##########################################
               case "envoyer_sql":
               envoyer_sql();
               break;

               default:
               creer_sql();
               break;
}
##########################################


include("foot.php");
?>